package com.studentsys.utils;

public class CurrentPage {
    private int totalCount;//总记录数
    private int pageSize;//页容量
    private int currentPage;//当前页
    private int startIndex;//每页第一条记录起始下标
    private int totalPage;//总页数
    private int prePage;//上一页
    private int nextPage;//下一页

    public CurrentPage() {
    }

    public CurrentPage(int totalCount, int pageSize, String currentPage) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        initCurrentPage(currentPage);
        initTotalPage();
        initStartIndex();
        initPrePage();
        initNextPage();
    }
    //给当前页面初始化
    private void initCurrentPage(String currentPage){
        if (currentPage==null){
            this.currentPage=1;
        }else{
            this.currentPage=Integer.parseInt(currentPage);
        }
    }
    //计算总页数
    private void initTotalPage(){
        this.totalPage=(this.totalCount%this.pageSize==0)?(this.totalCount/this.pageSize):(this.totalCount/this.pageSize+1);
    }
    //计算每一页的起始下标
    private void initStartIndex(){
        this.startIndex=this.pageSize*(this.currentPage-1);
    }
    //计算上一页
    private void initPrePage(){
        if (this.currentPage==1){
            this.prePage=1;
        }else{
            this.prePage=this.currentPage-1;
        }
    }
    //计算下一页
    private void initNextPage(){
        if (this.currentPage==this.totalPage){
            this.nextPage=this.totalPage;
        }else{
            this.nextPage=this.currentPage+1;
        }
    }


    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }
}
